<template>
    <div>
      <el-form :inline="true" class="demo-form-inline"  >
          <el-row>
              <p><b>首页</b>/住院部/出院申请表</p>
          </el-row>
  <br>
          <el-row>
              <el-col :span="3">  
              <el-form-item >
                  <el-select placeholder="请选择医生" v-model="param.workerId">
                  <el-option :label="inpatientStaff.wkName" :key="inpatientStaff.id" :value="inpatientStaff.id" v-for="inpatientStaff in inpatientStaffList"></el-option>
                  </el-select>
              </el-form-item>
              </el-col> 
  
              <el-col :span="3">
                  <el-form-item >
                  <el-input placeholder="请输入病人" v-model="param.patientName"></el-input>
                  </el-form-item>
              </el-col>
  
              <el-col :span="3">
                  <el-form-item >
                  <el-select placeholder="请选择科室" v-model="param.departmentId">
                  <el-option :label="inpatientDepartment.deName" :key="inpatientDepartment.id" :value="inpatientDepartment.id" v-for="inpatientDepartment in inpatientDepartmentList"></el-option>
                  </el-select>
                  </el-form-item>
              </el-col>
  
              <el-col :span="5">
                  <el-form-item >
                      <el-radio v-model="param.status" label=0>未结算</el-radio>
                      <el-radio v-model="param.status" label=2>办理出院</el-radio>
                      <el-radio v-model="param.status" label=3>已完成</el-radio>
                  </el-form-item>
              </el-col>
  
              <el-col :span="4">
                  <el-form-item >
                      <el-date-picker
                      v-model="valuedate"
                          type="daterange"
                          range-separator="至"
                          start-placeholder="开始日期"
                          end-placeholder="结束日期"
                          value-format="yyyy-MM-dd">
                      </el-date-picker>
                  </el-form-item>
              </el-col>
  
              <el-col :span="3" :offset="2">
                  <el-form-item>
                      <el-button type="primary" @click="queryGoOutRequestBtn">查询</el-button>
                      <el-button @click="resetForm">清空</el-button>
                  </el-form-item>
              </el-col>
          </el-row> 
      </el-form>
  
      <el-row>
          <el-table
              :data="tableData"
              style="width: 100%"
              >
              <el-table-column
              fixed
              prop="patientName"
              label="病人"
              >
              </el-table-column>
              <el-table-column
              prop="departmentName"
              label="住院科室"
              >
              </el-table-column>
              <el-table-column
              prop="workerName"
              label="申请医师"
              >
              </el-table-column>
              <el-table-column
              prop="requestTime"
              label="申请日期"
              >
              </el-table-column>
             
              <el-table-column
              fixed="right"
              label="操作"
              >
              <template slot-scope="scope">
                  
                  <el-button v-if="scope.row.status==0" type="danger" :disabled="scope.row.status=='2' ? false:true">
                  未结算
                  </el-button>
                  <el-button v-if="scope.row.status==1" type="info" :disabled="scope.row.status=='2' ? false:true">
                  待确定
                  </el-button>
                  <el-button v-if="scope.row.status==2" type="success" :disabled="scope.row.status=='2' ? false:true" @click="goOutHospitalBtn(scope.row.bedId,scope.row.ilId)">
                  办理出院
                  </el-button>
                  <el-button v-if="scope.row.status==3" type="info" :disabled="scope.row.status=='2' ? false:true">
                  已完成
                  </el-button>
              </template>
              </el-table-column>
          </el-table>
      </el-row>
  
      <el-row>
        <el-col>
          <el-pagination
                  background
                  :page-sizes="[3, 5, 10, 30]"
                  :page-size="pageSize"
                  :current-page="pageNum"
                  layout="prev, pager, next, total, sizes"
                  :total="total"
                  @next-click="nextPage"
                  @prev-click="prevPage"
                  @current-change="changePage"
                  @size-change="changeSize"
                  >
          </el-pagination>
        </el-col>
      </el-row>
  
  </div>
  </template>
  
  <script>
  
  export default {
    data() {
      return {
          tableData: [{
          }],

          inpatientStaffList:[],
          inpatientDepartmentList:[],
          param:{
            status:""
          },
          valuedate:'',
          pageSize:5,
          pageNum:1,
          total:0,
          goOutHospitalInfo:{},
  
      }
    },
  
    methods: {
      queryInpatientStaff(){
        this.$axios.get("api/request/queryInpatientStaff").then(resp=>{
          if(resp.data.code==200){
            this.inpatientStaffList=resp.data.data
          }
        })
      },
  
      queryInpatientDepartment(){
        this.$axios.get("api/request/queryInpatientDepartment").then(resp=>{
          if(resp.data.code==200){
            this.inpatientDepartmentList=resp.data.data
          }
        })
      },
  
      queryGoOutRequestBtn(){
        this.param.startTime=this.valuedate[0]
        this.param.endTime=this.valuedate[1]
        let pageData={}
        pageData.pageSize=this.pageSize
        pageData.pageNum=this.pageNum
        pageData.param=this.param
        this.$axios.post('api/goOut/queryGoOutRequestBtn',pageData).then(resp=>{
          if(resp.data.code==200){
            
            this.tableData=resp.data.data.list
            this.total=resp.data.data.total
            // console.log(resp.data)
          }
        })
      },

      goOutHospitalBtn(bedId,ilId){
        this.goOutHospitalInfo.bedId=bedId
        this.goOutHospitalInfo.ilId=ilId
        this.$axios.post('api/goOut/goOutHospitalBtn',this.goOutHospitalInfo).then(resp=>{
            if(resp.data.code==200){
                this.$message({
                showClose: true,
                message: '办理出院成功',
                type: 'success'
            });
            this.queryGoOutRequestBtn()
        }
        })
      },
  
      //下一页方法
      nextPage(val){
                      //回调参数val,val等于当前页码
                      this.pageNum=val
                      this.queryGoOutRequestBtn()
      },
      //上一页方法
      prevPage(val){
                      //回调参数val,val等0.于当前页码
                      this.pageNum=val
                      this.queryGoOutRequestBtn()
      },
      changePage(val){
                      this.pageNum=val
                      this.queryGoOutRequestBtn()
      },
      changeSize(val){
                      this.pageSize=val
                      this.pageNum=1
                      this.queryGoOutRequestBtn()
      },
      resetForm(){
        this.param.workerId=''
        this.param.patientName=''
        this.param.departmentId=''
        this.param.status=''
        this.valuedate=''
      },
  
    },
  
    created(){
        this.queryInpatientStaff()
        this.queryInpatientDepartment()
        this.queryGoOutRequestBtn()
    }
  }
  </script>
  
  <style scoped>
  
  </style>